#ifndef __Serial_Plot_H__
#define __Serial_Plot_H__

#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include "stm32f4xx_hal.h"
#include "Drivers/Components/drv_uart.h"

class Serial_Plot
{
    public:
        static const uint16_t NAME_LENGTH = 50;

    private:
        static UART_HandleTypeDef *huart;
        static const uint16_t Uart_Rx_Buff_Size = 100;
        static uint8_t Uart_Rx_Buff[Uart_Rx_Buff_Size];
        static const uint16_t Uart_Tx_Buff_Size = 100;
        static uint8_t Uart_Tx_Buff[Uart_Tx_Buff_Size];
        static const uint8_t SendPacketHead[];
        static uint16_t Send_Buff_Offset;

        static uint32_t Recived_Serial_Plot(uint8_t *dat, uint16_t len);
        static void get_variable(unsigned char *dat, unsigned char len, unsigned char *variable_name, float *variable_value);
        static int is_variable(char str[], uint16_t Num, char (*name_list)[NAME_LENGTH]);

        static char (*Variable_Assignment_List)[NAME_LENGTH];
        static uint16_t Variable_Assignment_Num;
        static void (*Variable_Assignment_Callback)(uint16_t index, float value);
        static void (*Variable_Send_Packet)(void);

        char (*Temp_Var_List)[NAME_LENGTH];
        uint16_t Temp_Var_Num;
        void (*Temp_Var_Callback)(uint16_t index, float value);
        void (*Temp_Var_Packet)(void);

    public:
        Serial_Plot(
            char (*_Variable_Assignment_List)[NAME_LENGTH],
            uint16_t Variable_Assignment_Num,
            void (*Variable_Assignment_Callback_f)(uint16_t index, float value),
            void (*Variable_Send_Packet_f)(void));

        static void Uart_init(UART_HandleTypeDef *_huart);
        void Select_this_Packet(void);
        static void Add_Var(float);
        static void Send_Packet(void);
};

extern Serial_Plot serial_plot;

#endif

/************************ COPYRIGHT(C) USTC-ROBOWALKER **************************/
